package com.lisx.module_time_block.dialogfragment;

import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.fenghuajueli.lib_data.constants.EventBusConstants;
import com.fenghuajueli.lib_data.entity.db.DayPlanDbEntity;
import com.fenghuajueli.lib_data.entity.eventbus.EventEntity;
import com.fenghuajueli.libbasecoreui.manager.TimeBlockManager;
import com.ijianji.lsx_ui_lib.BaseDialogFragment;
import com.lisx.module_time_block.R;
import com.lisx.module_time_block.utils.TimeUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.TimeZone;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class DakaDialogFragment extends BaseDialogFragment {

    DayPlanDbEntity entity;

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_fragment_daka;
    }

    @Override
    public void initView(Context context, View view, AttributeSet attributeSet) {
        TextView tvTitle = view.findViewById(R.id.tv_title);
        EditText etMsg = view.findViewById(R.id.et_msg);
        ImageView ivDaka = view.findViewById(R.id.iv_daka);
        RelativeLayout rlDaka = view.findViewById(R.id.rl_daka);
        etMsg.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString().trim())) {
                    ivDaka.setImageResource(R.drawable.aa_btn_nor_wancheng);
                    rlDaka.setEnabled(false);
                } else {
                    ivDaka.setImageResource(R.drawable.aa_btn_act_wancheng);
                    rlDaka.setEnabled(true);
                }
            }
        });
        rlDaka.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onDaka(etMsg.getText().toString().trim());
                }
                dismiss();
            }
        });
        view.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        if (entity != null) {
            tvTitle.setText(entity.getPlan_name());
            if (!TextUtils.isEmpty(entity.getMsg())) {
                etMsg.setText(entity.getMsg());
            }
        }
    }

    @Override
    public void initData(Context context) {

    }

    @Override
    public void initEvent(Context context) {

    }

    @Override
    public int getGravity() {
        return Gravity.BOTTOM;
    }

    public void setData(DayPlanDbEntity entity) {
        this.entity = entity;
    }

    public interface OnDakaListener{
        void onDaka(String msg);
    }

    OnDakaListener listener;

    public void setOnDakaListener(OnDakaListener listener) {
        this.listener = listener;
    }

}
